import { redirect } from "next/navigation";

import { ScheduleView } from "@/components/schedule/schedule-view";
import { getAuthenticatedUser, getProjectSummaries } from "@/lib/server-data";

export default async function SchedulePage() {
  const user = await getAuthenticatedUser();

  if (!user) {
    redirect("/auth/login");
  }

  const projects = await getProjectSummaries();

  return (
    <section className="mx-auto flex w-full max-w-5xl flex-col gap-6 px-6 py-12">
      <div className="flex flex-col gap-4">
        <h1 className="text-2xl font-semibold">排产计划</h1>
        <p className="text-sm text-muted-foreground">
          浏览各项目的目标产值、当前进度以及排产负责人。后续迭代将提供编辑与导入功能。
        </p>
      </div>
      <ScheduleView initialProjects={projects} />
    </section>
  );
}
